package com.example.javadocsearcher.entity;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: homechen
 * Date: 2024-03-06
 * Time: 20:19
 */

import lombok.Data;

import java.io.Serializable;

/**
 * 作为统一的返回结果
 */
@Data
public class AjaxResult implements Serializable {
    private int code; // 返回状态码
    private Object data; // 返回数据

    private String message;// 返回结果的描述

    public static AjaxResult success(Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(200);
        result.setData(data);
        result.setMessage("");
        return result;
    }

    public static AjaxResult success(int code, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setData(data);
        result.setMessage("");
        return result;
    }

    public static AjaxResult success(int code, String message, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }

    public static AjaxResult fail(int code, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setData(data);
        result.setMessage(null);
        return result;
    }

    public static AjaxResult fail(int code, String message, Object data) {
        AjaxResult result = new AjaxResult();
        result.setCode(code);
        result.setData(data);
        result.setMessage(message);
        return result;
    }
}
